package com.nowcoder.code.hjnc;

import com.algorithm.model.ListNode;

public class NC53 {

    public ListNode removeNthFromEnd(ListNode head, int n) {

        ListNode ans = new ListNode(0);
        ans.next = head;
        head = ans;
        ListNode fast = ans;
        for (int i = 0; i < n; i++) {
            fast = fast.next;
        }

        while (fast != null) {
            fast = fast.next;
            head = head.next;
        }


        head.next = head.next.next;

        return ans.next;
    }

}
